using UnityEngine;
using UnityEngine.InputSystem;

public class InputController : Singleton<InputController> {

    // 移动输入向量
    public Vector2 MoveInput { get; private set; }
    // 跳跃输入标志位
    public bool JumpJustPressed { get; private set; }
    public bool JumpBeingHeld { get; private set; }
    public bool JumpReleased { get; private set; }
    // 攻击输入标志位
    public bool AttackInput { get; private set; }
    // 冲刺输入标志位
    public bool DashInput { get; private set; }
    // 菜单打开/关闭输入标志位
    public bool MenuopencloseInput { get; private set; }

    private PlayerInput _playerInput;
    private InputAction _moveAction;
    private InputAction _jumpAction;
    private InputAction _attackAction;
    private InputAction _dashAction;
    private InputAction _menuOpenCloseAction;

    public override void Awake() {
        base.Awake();
        
    }

    private void Start() {
        _playerInput = GetComponent<PlayerInput>();
        SetupInputActions();
    }

    private void Update()
    {
        // 每帧更新输入状态
        UpdateInputs();
    }

    private void SetupInputActions()
    {
        // 从PlayerInput组件初始化输入动作
        _moveAction = _playerInput.actions["Move"];
        _jumpAction = _playerInput.actions["Jump"];
        _attackAction = _playerInput.actions["Attack"];
        _dashAction = _playerInput.actions["Dash"];
        // _menuOpenCloseAction = _playerInput.actions["MenuOpenclose"];
    }

    private void UpdateInputs()
    {
        // 更新特定的输入数值
        MoveInput = _moveAction.ReadValue<Vector2>(); // 读取移动输入值
        JumpJustPressed = _jumpAction.WasPressedThisFrame(); // 检测跳跃是否刚按下
        JumpBeingHeld = _jumpAction.IsPressed(); // 检测跳跃是否正在按住
        JumpReleased = _jumpAction.WasReleasedThisFrame(); // 检测跳跃是否刚释放
        AttackInput = _attackAction.WasPressedThisFrame(); // 检测攻击是否刚按下
        DashInput = _dashAction.WasPressedThisFrame(); // 检测冲刺是否刚按下
        // MenuOpenCloseInput = _menuOpenCloseAction.WasPressedThisFrame(); // 检测菜单打开/关闭是否刚按下
    }
}
